package com.example.attendancesystem.Util;/*
package com.example.demo.Util;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.springframework.util.ClassUtils;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Excel {


    */
/**
     * 创建学生信息表格
     * @param students
     *//*

    public static void creatStudentExcel(List<Student> students, String fileName) {
        String[] title = {"学生ID", "学号", "姓名", "性别", "年龄"};
        String resourcePath = ClassUtils.getDefaultClassLoader().getResource("").getPath();
        String savePath = resourcePath + "/static/downLoad";
        File path = new File(savePath);
        //3、路径不存在 创建一个目录
        if (!path.exists()) path.mkdirs();
        File file = new File(resourcePath+"/static/downLoad/"+fileName);
        try {
            if (file.exists()) {//文件存删除文件
                file.delete();
            }
            //创建一个新文件
            file.createNewFile();
            WritableWorkbook workbook = Workbook.createWorkbook(file);
            WritableSheet sheetA = workbook.createSheet("sheet1", 0);
            Label labelA = null;
            //添加标题
            for (int i = 0; i < title.length; i++) {
                labelA = new Label(i, 0, title[i]);
                sheetA.addCell(labelA);
            }
            //写入数据
            int i = 1;
            for (Student student : students) {
                labelA = new Label(0, i, "" + student.getId());
                sheetA.addCell(labelA);
                labelA = new Label(1, i, "" + student.getNumber());
                sheetA.addCell(labelA);
                labelA = new Label(2, i, "" + student.getName());
                sheetA.addCell(labelA);
                labelA = new Label(3, i, "" + student.getGender());
                sheetA.addCell(labelA);
                labelA = new Label(4, i, "" + student.getAge());
                sheetA.addCell(labelA);
                i++;
            }
            workbook.write();
            workbook.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }

    */
/**
     * 文件下载功能
     *
     * @param response
     * @param fileName
     * @return
     *//*

    public static String downLoadFile(HttpServletRequest request, HttpServletResponse response, String fileName,File file) throws UnsupportedEncodingException {
        response.reset();
        response.setCharacterEncoding("UTF-8");
        response.setContentType("application/octet-stream");//Mac的Safari
        response.setContentType("application/x-download");//三大主流浏览器 IE Firefox Google
        response.addHeader("Content-Disposition", "attachment;fileName=" + new String(fileName.getBytes("UTF-8"),"ISO-8859-1"));// 设置文件名
        byte[] buffer = new byte[1024];
        FileInputStream fis = null;
        BufferedInputStream bis = null;
        try {
            fis = new FileInputStream(file);
            bis = new BufferedInputStream(fis);
            OutputStream os = response.getOutputStream();
            int i = bis.read(buffer);
            while (i != -1) {
                os.write(buffer, 0, i);
                i = bis.read(buffer);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (bis != null) {
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fis != null) {
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

    */
/**
     * 读取Excel表格内容保存到列表中 返回一个集合
     * @return
     *//*

    public static ArrayList<ArrayList> importExcel(String fileName) {
        ArrayList<ArrayList> aa = new ArrayList<>();
        try {
            String resourcePath = ClassUtils.getDefaultClassLoader().getResource("").getPath();
            File file = new File(resourcePath + "/static/importFile/"+fileName);
            Workbook workbook = Workbook.getWorkbook(new FileInputStream(file));
            Sheet sheetA = workbook.getSheet(0);
            for (int i = 0; i < sheetA.getRows(); i++) {
                ArrayList a = new ArrayList<>();
                for (int j = 0; j < 5; j++) {
                    Cell cell = sheetA.getCell(j, i);
                    a.add(cell.getContents());
                }
                aa.add(a);
            }
            //读取文件后删除文件
            file.delete();
            return aa;
        }catch (Exception e){
            return aa;
        }
    }


}
*/
